iT邦幫忙

2024 iThome 鐵人賽

DAY 11
0
Mobile Development

畢業專題拯救計畫系列 第 11

Flutter中的工具包--Plugins and Third-Party Libraries

  • 分享至 

  • xImage
  •  

在 Flutter 開發中,Plugins and Third-Party Libraries 是非常重要的工具,它們提供了現成的功能和程式碼,讓我們不必從零開始 coding ,從而節省時間並提高效率。

  • 什麼是插件 (Plugins)?
    插件就像是小工具包。這些工具包由社群或開發者製作,能夠快速實現一些常見功能,而不需要自己從頭編寫。例如,使用地圖插件,就可以方便地在應用中嵌入地圖。

  • 什麼是第三方庫 (Third-Party Libraries)?
    第三方庫像是應用開發中的現成解決方案包。這些代碼包由其他開發者或團隊創建,專門用來解決某些特定的問題或簡化開發工作。舉例來說,http library 能單地處理網絡請求,而 provider library 則能管理應用程式狀態。

常見的插件和第三方庫

  • http: 用於進行網絡請求。
final response = await http.get(Uri.parse('https://example.com/api/data'));

if (response.statusCode == 200) {
  // 處理成功
  final data = response.body;
} else {
  // 處理錯誤
}
  • provider: 用於狀態管理。
class Counter with ChangeNotifier {
  int _count = 0;

  int get count => _count;

  void increment() {
    _count++;
    notifyListeners();
  }
}
final counter = Provider.of<Counter>(context);
  • shared_preferences: 用於本地數據存儲。
final prefs = await SharedPreferences.getInstance();
await prefs.setInt('counter', 10);

final counter = prefs.getInt('counter') ?? 0;

我們明天見~


上一篇
Flutter中的日記本--Local Storage
下一篇
Flutter中的Third-Party Libraries-- table_calendar
系列文
畢業專題拯救計畫22
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言